//Tire树做法
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<cstdlib>//rand()
#define rep(i,a,b) for(register int i = (a);i <= (b);++i)
#define per(i,a,b) for(register int i = (a);i >= (b);--i)
typedef long long ll;
typedef unsigned long long ull;
using std::string;using std::cin;using std::cout;

int n,len,tot,tire[500010][30],s[500010],ans;
bool flag[500010],flag2[500010];
string str;

inline void search(){
    int root = 0 , now = 1;
    ans = 1;
    while(now <= len){
        if(tire[root][s[now]] != 0) root = tire[root][s[now]] , ++now;
        else{
            ans = 0;
            return;
        }
    }
    if(flag[root] && !flag2[root]){
        flag2[root] = true;
        ans = 1;
        return;
    }
    if(flag[root] && flag2[root]){
        ans = 2;
        return;
    }    
    
}

inline void insert(){
    int root = 0 , now = 1;
    while(now <= len){
        if(tire[root][s[now]] != 0) root = tire[root][s[now]] , ++now;
        else tire[root][s[now]] = ++tot , ++now , root = tot;
    }
    flag[root] = true;
    return;
}

int main(){
    std::ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    //freopen("in.in", "r", stdin);

    cin >> n;
    rep(i,1,n){
        cin >> str;
        len = str.length();
        rep(i,1,len) s[i] = str[i-1] - 'a' + 1;
        insert();
    }
    cin >> n;
    while(n--){
        cin >> str;
        len = str.length();
        rep(i,1,len) s[i] = str[i-1] - 'a' + 1;
        search();
        if(ans == 0) cout << "WRONG\n";
        else if(ans == 1) cout << "OK\n";
        else if(ans == 2) cout << "REPEAT\n";
    }

    return 0;
}